import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

import {
  UPDATE_INFO
} from './mutation-types'

const store = new Vuex.Store({
  state: {
    info: {
      name: '科比',
      age: 1979,
      height: 1.98
    }
  },
  mutations: {
    aUpdateInfo(state) {
      setTimeout(() => {
        state.info.age = 44
      }, 1000);
    }
  },
  actions: {
    // context是和store对象具有相同方法和属性的对象
    // cpntext理解为store对象
    aUpdateInfo(context) {
      // 错误方法，修改state的唯一方法是mutation
      // context.state.info.name = '张三'

      setTimeout(() => {
        // store里面有commit
        context.commit('aUpdateInfo')
      }, 1000)
    }
  }
})

export default store
